package vn.intelsoft.vlogvn;

import android.os.Bundle;
import android.view.WindowManager;
import android.widget.Toast;

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.OnInitializedListener;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;

public class PlayerActivity extends YouTubeBaseActivity implements OnInitializedListener {

	private YouTubePlayerView ytpv;
	private YouTubePlayer ytp;
	private String id;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_player);
		
		id = getIntent().getExtras().getString("id");
		
		ytpv = (YouTubePlayerView) findViewById(R.id.youtubeplayer);
		ytpv.initialize("AIzaSyC-R09MYt2HS82nxKuFCzvNgC60DnxFcqM", this);
		if(ytp !=null){
			ytp.loadVideo(id);
			ytp.setFullscreen(true);
		}
	}

	@Override
	public void onInitializationFailure(Provider arg0,YouTubeInitializationResult arg1) {
		Toast.makeText(this, "Initialization Fail", Toast.LENGTH_LONG).show();
	}

	@Override
	public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasrestored) {
		ytp = player;
		if(ytp !=null){
			ytp.loadVideo(id);
			ytp.setFullscreen(true);
		}
	}
	
	
}
